package answer.service.Impl;

import answer.mapper.SpecialMapper;
import answer.pojo.WeekTem;
import answer.service.SpecialService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import commons.pojo.Special;
import commons.vo.LivegoodsResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SpecialServiceImpl implements SpecialService {
    @Autowired
    private SpecialMapper specialMapper;

    @Override
    public LivegoodsResult SpecialSearch() {
        Map<Object, Object> map = new HashMap<>();
        ArrayList<WeekTem> list = new ArrayList<>();
        List<Special> specials = specialMapper.selectList(null);
        for (int week = 0 ; week < specials.size();week++){
            if(list.size()!=0 && specials.get(week).getName().equals(list.get(list.size()-1).getName())){
                list.set(list.size()-1, new WeekTem(specials.get(week).getName(),specials.get(week).getTime()));
            }else {
                list.add(new WeekTem(specials.get(week).getName(),specials.get(week).getTime()));
            }
//            if(week == weeks.size()-1) list.set(list.size()-1,new WeekTem(haha(weeks.get(week).getYear()),weeks.get(week).getTime()));
        }
        map.put("专项答题",list);
        return LivegoodsResult.ok(map);
    }

    @Override
    public LivegoodsResult SpecialAnswer(String name, int n) {
        QueryWrapper<Special> objectQueryWrapper = new QueryWrapper<>();
        objectQueryWrapper.eq("name",name);
        objectQueryWrapper.eq("time",n);
        List<Special> list = specialMapper.selectList(objectQueryWrapper);
//        List<Special> list = specialMapper.selectSpecial(name, n);
        return LivegoodsResult.ok(list);
    }
}
